#!/bin/bash
source /etc/profile
source ~/.bash_profile

#打印时间
cur_dateTime=$(date "+%Y-%m-%d_%H:%M:%S")

#定义变量
logfile_resoult=tpcc_resoult.log
logfile_createdata=rundata.log
file_dir=/opt/tpcc/benchmarksql5.0-mysql/


#清空上次的日志文件
cd ${file_dir}run
> ${logfile_resoult}
> ${logfile_createdata}

#创建数据
cd ${file_dir}run
./runDatabaseDestroy.sh tpcc.3t >> ${logfile_createdata}
./runDatabaseBuild.sh tpcc.3t >> ${logfile_createdata}

#执行tpcc测试，并将结果写入文件
cd ${file_dir}run
echo ${cur_dateTime} | tee -a ${logfile_resoult}
./runBenchmark.sh tpcc.3t | tee -a ${logfile_resoult}

#确认测试记录汇总表存在
if test -f "reportAll.csv"; then
	echo "${cur_dateTime} reportAll.csv"
else
	echo """TestTime,TestIP,warehouses,terminals,runMins,Tpmc""" >>  "${file_dir}run/reportAll.csv"
fi

#获取单个测试报告数据
TEST_REPORT_LINE_warehouses3=`cat ${file_dir}run/${logfile_resoult} |grep warehouses`
TEST_REPORT_LINE_terminals3=`cat ${file_dir}run/${logfile_resoult} |grep terminals`
TEST_REPORT_LINE_runMins3=`cat ${file_dir}run/${logfile_resoult} |grep runMins`
TEST_REPORT_LINE_tpmc3=`cat ${file_dir}run/${logfile_resoult} |grep tpmC`


#填充测试记录表,##*= 就是把字符串=右边的值取出来，左边的删掉
echo """${cur_dateTime},${TEST_REPORT_LINE_warehouses3##*=},${TEST_REPORT_LINE_terminals3##*=},${TEST_REPORT_LINE_runMins3##*=},${TEST_REPORT_LINE_tpmc3##*=}"""  >> "${file_dir}run/reportAll.csv"
